<template>
    <div class="add-page">
        <!-- Header组件 -->
        <Header>
            <template v-slot:left>
                <span @click="$router.go(-1)">&lt;</span>
            </template>
            <template v-slot:middle>
                新增地址
            </template>
        </Header>
        
        <!-- 表单 -->
        <div class="line">
            <div class="label">联系人</div>
            <!-- <input type="text" placeholder="姓名" ref="name"> -->
            <input type="text" placeholder="姓名" v-model="name">
        </div>
        <div class="line">
            <div class="label">电话</div>
            <input type="text" placeholder="手机号码" v-model="phone">
        </div>
        <div class="line">
            <div class="label">地址</div>
            <input type="text" placeholder="收货地址" v-model="address">
        </div>

        <!-- 按钮 -->
        <div class="btn-box">
            <!-- 点击保存按钮,调用从vuex的mutations中注入的add方法,实现新增地址功能. -->
            <div class="btn" @click="add( $data )">保存并使用</div>
        </div>
        
    </div>
</template>

<script>
import {mapMutations} from 'vuex'

export default {
    data(){
        return {
            name:'',
            address:'',
            phone:''
        }
    },
    methods:{
        ...mapMutations(['add']),
    }
}
</script>
<style scoped >
.line{
    display: flex;
    margin: 0 20px;
    padding: 20px 0;
    border-bottom: 1px solid #f0f0f0;
}
.line .label{
    width: 100px;
}
.line input{
    flex: 1;
    border: none;
    outline: none;

}

.btn-box{
    margin: 20px;
}
.btn-box .btn{
    line-height: 50px;
    text-align: center;
    color: white;
    background-color: lightskyblue;
}
</style>